package com.woniu.login.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.common.entity.AdmAccount;
import com.woniu.common.entity.AdmEmployee;
import com.woniu.common.entity.Result;
import com.woniu.login.mapper.AccountMapper;
import com.woniu.login.mapper.LoginMapper;
import com.woniu.login.service.AccountService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    LoginMapper loginMapper;
    @Autowired
    AccountMapper accountMapper;
    //  分页查询
    public IPage<AdmAccount> getAll (int page, int size, AdmAccount admAccount) {

        Page<AdmAccount> npage = new Page<>(page, size);
        QueryWrapper<AdmAccount> queryWrapper = new QueryWrapper<AdmAccount>();
        // 检查username是否不为空，如果非空，则添加like条件
        if (StringUtils.isNotBlank(admAccount.getAaname())) {
            queryWrapper.like("aaname", admAccount.getAaname());
        }
        if (StringUtils.isNotBlank(admAccount.getAapassword())) {
            queryWrapper.like("aapassword", admAccount.getAapassword());
        }
        if (StringUtils.isNotBlank(admAccount.getAanumber())) {
            queryWrapper.like("aanumber", admAccount.getAanumber());
        }
        if (StringUtils.isNotBlank(admAccount.getAaemail())) {
            queryWrapper.like("aaemail", admAccount.getAaemail());
        }
        if (StringUtils.isNotBlank(admAccount.getAatype())) {
            queryWrapper.like("aatype", admAccount.getAatype());
        }
        if (StringUtils.isNotBlank(admAccount.getAauser())) {
            System.out.println("admAccount.getuser："+admAccount.getAauser());
            queryWrapper.like("aauser", admAccount.getAauser());
        }
        IPage<AdmAccount> accountIPage = accountMapper.selectPage(npage, queryWrapper);
        return accountIPage;
    }
    //    修改账号信息
    @Override
    public Result update(AdmAccount admAccount) {
        accountMapper.update(admAccount, new QueryWrapper<AdmAccount>()
                .eq("aaid", admAccount.getAaid()));
        return Result.ok("修改成功");
    }


}
